﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using Isuka.Spiritual.Auxiliaries;

namespace Isuka.Spiritual
{
    public sealed partial class RuleHolder<T, A> : IRule<T, A>
        where T : IEquatable<T>
        where A : class
    {
        /// <summary>
        /// コンストラクター
        /// </summary>
        /// <param name="rule"></param>
        public RuleHolder(Rules<T, A>.RuleFunc rule)
        {
            Contract.Requires<ArgumentNullException>(rule != null, "rule");

            Rule = rule;
        }

        #region IRule<T,A> メンバー

        public Rules<T, A>.RuleFunc Rule
        {
            get;
            set;
        }

        #endregion

        #region Operators

        public RuleHolder<T, A> this[Action<A> action]
        {
            get
            {
                Contract.Requires(action != null);
                Contract.Ensures(Contract.Result<RuleHolder<T, A>>() != null);

                return new RuleHolder<T, A>(Rule.Act(action));
            }
        }

        public RuleHolder<T, A> this[Action<A, T> action]
        {
            get
            {
                Contract.Requires(action != null);
                Contract.Ensures(Contract.Result<RuleHolder<T, A>>() != null);

                return new RuleHolder<T, A>(Rule.Act(action));
            }
        }

        #endregion
    }
}
